package com.hmall.trade.listener;

import com.hmall.common.constants.MqConstants;
import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 监听支付结果
 *
 * @Author katana
 * @Date 2025/6/21 18:03
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class PayStatusListener {
    
    private final IOrderService orderService;
    
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.PAY_SUCCESS_QUEUE, durable = "true"),
            exchange = @Exchange(name = MqConstants.PAY_EXCHANGE_NAME, type = "direct"),
            key = MqConstants.PAY_SUCCESS_KEY
    ))
    public void listenPaySuccess(Long orderId){
        orderService.markOrderPaySuccess(orderId);
        log.info("监听到订单支付成功消息，订单id：{}", orderId);
    }
    
}
